package com.jingtai.shop.service.goods.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jingtai.common.enums.DeleteFlagEnum;
import com.jingtai.common.enums.GoodsStatusEnum;
import com.jingtai.common.enums.RecommendedStatusEnum;
import com.jingtai.core.entity.shop.MerchantsGoods;
import com.jingtai.core.mapper.shop.MerchantsGoodsMapper;
import com.jingtai.shop.service.goods.MerchantsGoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 商户商品表 服务实现类
 * </p>
 *
 * @author GR123
 * @since 2020-11-29
 */
@Service
public class MerchantsGoodsServiceImpl extends ServiceImpl<MerchantsGoodsMapper, MerchantsGoods> implements MerchantsGoodsService {

    @Resource
    private MerchantsGoodsService goodsService;
    @Resource
    private MerchantsGoodsMapper goodsMapper;

    /**
     * 首页 推荐商品(优选)
     */
    @Override
    public Page<MerchantsGoods> pageGoodsByRecommend(Long pageNo, Long pageSize) {
        return goodsService.page(new Page<>(pageNo, pageSize), Wrappers.lambdaQuery(MerchantsGoods.class)
                .eq(MerchantsGoods::getGoodsState, GoodsStatusEnum.NORMAL.getStatus())
                .eq(MerchantsGoods::getRecommendedState, RecommendedStatusEnum.PREFERRED.getStatus())
                .eq(MerchantsGoods::getDeleteFlag, DeleteFlagEnum.NOT_DELETE.getCode()));
    }

    /**
     * 首页关键字搜索商品
     */
    @Override
    public Page<MerchantsGoods> searchMerchantsGoods(String keyword, Long pageNo, Long pageSize) {
        return goodsMapper.pageGoodsByKeyWord(new Page<>(pageNo,pageSize),keyword);
    }

    /**
     * 三级分类id 查询商品列表
     */
    @Override
    public Page<MerchantsGoods> pageGoodsByLevel(Long threeId, Long pageNo, Long pageSize) {
        return goodsService.page(new Page<>(pageNo, pageSize), Wrappers.lambdaQuery(MerchantsGoods.class)
                .eq(MerchantsGoods::getGoodsState, GoodsStatusEnum.NORMAL.getStatus())
                .eq(MerchantsGoods::getCategoryId,threeId)
                .eq(MerchantsGoods::getDeleteFlag, DeleteFlagEnum.NOT_DELETE.getCode()));
    }
}
